package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallGoodsAccessoryGroupMapper;
import org.linlinjava.litemall.db.domain.LitemallGoods;
import org.linlinjava.litemall.db.domain.LitemallGoodsAccessoryGroup;
import org.linlinjava.litemall.db.domain.LitemallGoodsAccessoryGroupExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class LitemallGoodsAccessoryGroupService {
    @Resource
    private LitemallGoodsAccessoryGroupMapper litemallGoodsAccessoryGroupMapper;

    public void add(LitemallGoodsAccessoryGroup goodsAccessoryGroup){
        goodsAccessoryGroup.setAddTime(LocalDateTime.now());
        goodsAccessoryGroup.setUpdateTime(LocalDateTime.now());
        goodsAccessoryGroup.setDeleted(false);
        litemallGoodsAccessoryGroupMapper.insert(goodsAccessoryGroup);
    }

    public List<LitemallGoodsAccessoryGroup> findBySameName(String accessoryGroupName,Integer goodsId){
        LitemallGoodsAccessoryGroupExample example = new LitemallGoodsAccessoryGroupExample();
        example.createCriteria().andNameEqualTo(accessoryGroupName).andGoodsIdEqualTo(goodsId);

        return litemallGoodsAccessoryGroupMapper.selectByExample(example);
    }

    public List<LitemallGoodsAccessoryGroup> findByName(String accessoryGroupName){
        LitemallGoodsAccessoryGroupExample example = new LitemallGoodsAccessoryGroupExample();
        example.createCriteria().andNameLike("%"  + accessoryGroupName + "%");

        return litemallGoodsAccessoryGroupMapper.selectByExample(example);
    }

    public List<LitemallGoodsAccessoryGroup> queryByGid(Integer goodsId){
        LitemallGoodsAccessoryGroupExample example = new LitemallGoodsAccessoryGroupExample();
        example.createCriteria().andGoodsIdEqualTo(goodsId);

        return litemallGoodsAccessoryGroupMapper.selectByExample(example);
    }

}
